<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
    String path = request.getContextPath(); //web项目的根路径
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<link rel="stylesheet" href="js/layui2.4.5/css/layui.css">
<script src="<%=basePath  %>js/jquery.min.js"></script>
<script src="<%=basePath  %>js/layui2.4.5/layui.js"></script>
</head>
<body>


<div class="layui-form"  style="padding: 20px 30px 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">用户ID</label>
    <div class="layui-input-inline">
    <c:if test="${not empty user}">
      <input type="text" name="userId" id="userId" placeholder="请输入" autocomplete="off" class="layui-input" readonly="readonly">
    </c:if>
     <c:if test="${empty user}">
      <input type="text" name="userId" id="userId" placeholder="请输入" autocomplete="off" class="layui-input">
    </c:if>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-inline">
    <c:if test="${not empty user}">
      <input type="text" name="userName" id="userName" placeholder="请输入" autocomplete="off" class="layui-input" readonly="readonly">
  	</c:if>
  	<c:if test="${ empty user}">
      <input type="text" name="userName" id="userName" placeholder="请输入" autocomplete="off" class="layui-input">
  	</c:if>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-inline">
    <c:if test="${not empty user}">
      <input type="text" name="userPassword" id="userPassword"  placeholder="请输入" autocomplete="off" class="layui-input" readonly="readonly">
    </c:if>
     <c:if test="${ empty user}">
      <input type="text" name="userPassword" id="userPassword"  placeholder="请输入" autocomplete="off" class="layui-input">
    </c:if>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
    <c:if test="${not empty user}">
      <input type="hidden" button lay-submit lay-filter="go" value="确认" class="layui-btn">
     </c:if>
     <c:if test="${ empty user}">
      <input type="button" button lay-submit lay-filter="go" value="编辑" class="layui-btn">
     </c:if>
    </div>
  </div>
</div>

<script>
     function child(data) {
    	$("#userId").val(data.userId);
    	$("#userName").val(data.userName);
    	$("#userPassword").val(data.userPassword);
    }
    
	layui.use('form', function(){
		  var form = layui.form;
		  form.on('submit(go)', function(data){
			  console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
			   $.ajax({  
					type : "post",  //提交方式  
					url : "<%=basePath %>updateByUserId",//路径  
					data : data.field,
					success : function(result) { //返回数据根据结果进行相应的处理 
						if (result.success) {  
							 parent.$("#successNumber").val(1)
							 parent.$("#name").val(data.field.userName)
							 parent.layer.msg('修改完成', {icon: 6})
							
							 var index = parent.layer.getFrameIndex(window.name)
							 parent.layer.close(index)
							/*  
							 if(parent.$("#userName").val()!=''&&parent.$("#userName").val()!=null){
								 parent.$("#userName").val($("#userName").val())
								 parent.$("#searchBtn").click()
							 }
							 parent.$(".layui-laypage-btn").click() */
						} else {  
						    parent.$("#successNumber").val('2')
							layer.alert("修改败请重试")
						}  
					} ,
					error:function(result){
						layer.alert("修改失败请重试")
			        }
					
				});
			  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
		  
		  //各种基于事件的操作，下面会有进一步介绍
		});
</script>



</body>
</html>